import { ClientApp, LifeCycle } from "./types";
import {ConsoleLogger} from './debug-log'
const console=new ConsoleLogger('微应用-子应用')
interface MicroClientBind{
  (name,props:LifeCycle):void;
  default?:LifeCycle;
}
/**
 * 
 * @param name 微应用子应用名称
 * @param props 
 */
 export const microClientBind:MicroClientBind=(name,props:LifeCycle)=>{
    if(window.__POWERED_BY_MICO__){
      try{
        const dic=window.__POWERED_BY_MICO__ ; 
        dic.activeAppDic[name].clientLife={bootstrap:props.bootstrap,mount:props.mount,unmount:props.unmount};
        microClientBind.default={bootstrap:props.bootstrap,mount:props.mount,unmount:props.unmount}
        console.log('执行子应用microClientBind绑定-子应用绑定',{bootstrap:props.bootstrap,mount:props.mount,unmount:props.unmount})
      }catch(e){
        console.log('执行绑定微应用失败',{error:e})
      }
  
    }else{
      throw new Error("主应用微应用初始化失败")
    }
  
  }
  //;(function(window, self){;${ scriptText }\n${ sourceUrl }}).bind(window.proxy)(window.proxy, window.proxy);